package com.chebaohui.iqs.service.impl.deal.util;

import java.util.List;

import com.chebaohui.iqs.config.InsuranceCode;
import com.chebaohui.iqs.entity.base.Insurance;

/**
 * 请求接口车险选择参数判断工具类
 * 
 * @author regas_xie
 *
 */
public class InsuranceUtil {

	/**
	 * 判断
	 * 
	 * @return
	 */
	public static String deal(List<Insurance> insuranceList) {
		boolean tp = false, bl = false, thr = false;
		
		for (Insurance i : insuranceList) {
			InsuranceCode c1 = get(i.getCode());
			if (null == c1)
				return "有符合接口要求的车险代码:" + i.getCode() + "," + i.getValue();

			if (!c1.isRely() && "true".equals(i.getIndemnity()))
				return "该车险没有不计免赔:" + c1.getCode() + "," + c1.getValue();

			if (i.getCode().equals(InsuranceCode.TP.getCode()))
				tp = true;
			else if (i.getCode().equals(InsuranceCode.BL.getCode()))
				bl = true;
			else if (i.getCode().equals(InsuranceCode.BTR.getCode()))
				thr = true;
		}

//		if (!tp)
//			return "未选择交强险";
	/*	if (!thr)
			return "未选择第三责任险";*/

		for (Insurance i : insuranceList) {
			if (i.getCode().equals(InsuranceCode.BN.getCode())) {
				if (!bl)
					return "选车身划痕损失险请先选择车损险";
			} else if (i.getCode().equals(InsuranceCode.BG.getCode())) {
				if (!bl)
					return "选玻璃单独破碎险请先选择车损险";
			} else if (i.getCode().equals(InsuranceCode.BR.getCode())) {
				if (!bl)
					return "选指定修理厂险请先选择车损险";
			} else if (i.getCode().equals(InsuranceCode.BNP.getCode())) {
				if (!bl)
					return "选自燃损失险请先选择车损险";
			} else if (i.getCode().equals(InsuranceCode.BW.getCode())) {
				if (!bl)
					return "选发动机涉水损失险请先选择车损险";
			}else if (i.getCode().equals(InsuranceCode.BTT.getCode())) {
				if(!bl)
					return "选第三方特约险请先选择车损险";
			}

		}

		return "true";
	}

	/**
	 * 判断车险
	 * 
	 * @param code
	 * @return
	 */
	public static InsuranceCode get(String code) {
		for (InsuranceCode i : InsuranceCode.values()) {
			if (code.equals(i.getCode()))
				return i;
		}
		return null;
	}
}
